<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<link rel="stylesheet" type="text/css" media="screen" href="../../css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" media="screen" href="../../css/dataTables.bootstrap.min.css">
<link rel="stylesheet" href="../../layui/css/layui.css" media="all" />

</head>
<body>
    <div>
        <div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
            <div>
                <header style="height: 100%">
                    <div align="left">
	                    <table style="width: 100%">
	                   		<tr>
	                   			<td>
<!--		                   			<form class="form-inline" onsubmit="return false">-->
<!--										<div class="form-group">-->
<!--											产品名称：-->
<!--											<input id="productName" name="productName" type="text" class="form-control" placeholder="产品名称">-->
<!--											<button id="searchBt" class="layui-btn layui-btn-sm" permission="sys:chanpin:query"><i class="layui-icon">&#xe615;</i>搜索</button>-->
<!--										</div>-->
<!--									</form>-->
	                   			</td>
	                   			<td align="right">
	                   				<button class="layui-btn layui-btn-sm" onclick="location.href='addSysChan.html'">
                                      <i class="layui-icon">&#xe608;</i> 添加
                                    </button>
	                   			</td>
	                   		</tr> 
	                    </table>
					</div>
                </header>
                
                <div>
                    <div class="widget-body no-padding">
                        <table id="dt-table" class="table table-striped table-bordered table-hover" style="width:100%">
                            <thead>
                                <tr>
                                </tr>                       
                                <tr>
									<th>产品名称</th>
									<th>设备数量</th>
									<th>创建时间</th>
									<th>节点类型</th>
									<th>productKey</th>
									<th>操作</th>
                                </tr>
                            </thead>
                            <tbody>
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
</body>
</html>

<script type="text/javascript" src="../../js/libs/jquery-2.1.1.min.js"></script>
<script type="text/javascript" src="../../js/jq.js"></script>
<script type="text/javascript" src="../../js/plugin/datatables/jquery.dataTables.min.js"></script>
<script type="text/javascript" src="../../js/plugin/datatables/dataTables.bootstrap.min.js"></script>
<script type="text/javascript" src="../../layui/layui.js"></script>
<script type="text/javascript" src="../../js/my/permission.js"></script>
<script type="text/javascript" src="../../layui/lay/modules/util.js"></script>
<script type="text/javascript">
var pers = checkPermission();

var example;
function init(){
	example = 
    	$('#dt-table').DataTable({
        	"searching": false,
        	"processing": false,
        	"serverSide" : true,
        	"language": {
                "url": "/js/plugin/datatables/Chinese.lang"
            },
        	"ajax": {
        		"url" : "/sysChans",
        		"type":"get",
        		"data":function(d){
    				d.id = $("#id").val();
    			}
        	},
        	"dom": "<'dt-toolbar'r>t<'dt-toolbar-footer'<'col-sm-10 col-xs-12 hidden-xs'i><'col-xs-12 col-sm-10' p v>>",	
            "columns": [
				{"data" : "productName", "defaultContent" : ""},
				{"data" : "deviceCount", "defaultContent" : ""},
				{
					"data" : "gmtCreate",
					"defaultContent" : "",
					"render": function (data, type, row) {
						var gmtCreate = row['gmtCreate'];
						gmtCreate = layui.util.toDateString(gmtCreate, "yyyy年MM月dd日");
						return gmtCreate;
					}
				},
				{
					"data" : "nodeType",
					"defaultContent" : "",
					"render": function (data, type, row) {
						var status = row['nodeType'];
						var a = "";
						if(status == 1){
							a = "网关";
						} else {
							a = "设备";
						}
						return a;
					}
				},
				{"data" : "productKey", "defaultContent" : ""},
				{ 
                    "data": "",
                    "defaultContent": "",
                    "orderable":false,
                    "render": function (data, type, row) {
                       var productKey = row['productKey'];
                       var href = "updateSysChan.html?productKey=" + productKey;
                       var edit = buttonEdit(href, "sys:chanpin:query", pers);
                       var del = buttonDel(productKey, "sys:chanpin:del", pers);
                       return edit + del;
                    }
                },
                
            ],
           "order": [[ 0, "asc" ]]
        } );
}

layui.use('layer', function(){
    var layer = layui.layer;
});

function del(productKey){
	layer.confirm('确定要删除吗？', {
        btn : [ '确定', '取消' ]
    }, function() {
    	$.ajax({
            type : 'delete',
            url : '/sysChans/'+productKey,
            success : function(data) {
                // layer.msg("删除成功");
                // example.ajax.reload();
                layer.msg('删除成功',{
                    time: 1500 //0.5秒关闭（如果不配置，默认是3秒）
                },function(){
                    example.ajax.reload();
                });
            }
        });
        layer.close(1);
    });
}

$("#searchBt").click(function(){
	example.ajax.reload();
});

init();
</script>
